#include <stdio.h>
#include <unistd.h>
#include <poll.h>

int main(void)
{
    struct pollfd fds[2] = {0};

    fds[0].fd = STDIN_FILENO;
    fds[0].events = POLLIN;

    //fds[1].fd = STDOUT_FILENO;
    //fds[1].events = POLLOUT;

    while (1)
    {
        int ret = poll(fds, 2, 5000);

        if (0 == ret)
        {
            printf("timeout\n");
        }
        else if (ret < 0)
        {
            perror("poll");
        }
        else
        {
            printf("ret = %d", ret);
            if (fds[0].revents & POLLIN)
            {
                printf(", stdin can read");
                char buf[1024];
                read(STDIN_FILENO, buf, 1024);
            }
            if (fds[1].revents & POLLOUT)
            {
                printf(", stdout can write");
            }
            printf("\n");
        }
    }
}